package com.meihua.shellapp.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.aspsine.irecyclerview.IViewHolder;
import com.meihua.shellapp.R;
import com.meihua.shellapp.bean.ClassRoomBean;
import com.meihua.shellapp.utils.PicassoUtils;

import java.util.List;


public class ClassroomrvAdapter extends RecyclerView.Adapter<IViewHolder> {
    private List<ClassRoomBean.DataBean> mData;

    public ClassroomrvAdapter(List<ClassRoomBean.DataBean> urls) {
        mData = urls;
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }

    private OnItemClickListener mOnItemClickListener;

    @Override
    public IViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_classroom, parent, false));
    }

    @Override
    public void onBindViewHolder(final IViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        ClassRoomBean.DataBean dataBean = mData.get(position);
        viewHolder.mTv.setText(dataBean.getTitle());
        PicassoUtils.getInstance().bindImageData(viewHolder.mIV, dataBean.getImg(),R.drawable.banner_place);
//        Picasso.with(holder.itemView.getContext()).load(Constant.IMGSTR + dataBean.getImg()).placeholder(R.drawable.ic_default).into(viewHolder.mIV);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final int position = holder.getIAdapterPosition();
                if (mOnItemClickListener != null) {
                    mOnItemClickListener.onItemClick(position, v);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mData != null ? mData.size() : 0;
    }

    class ViewHolder extends IViewHolder {
        public ImageView mIV;
        public TextView mTv;

        public ViewHolder(View itemView) {
            super(itemView);
            mIV = itemView.findViewById(R.id.item_con_iv);
            mTv = itemView.findViewById(R.id.item_con_tv);
        }
    }
}
